import Workspace from '../core/workspace.js';
import App from './app.js';

var demoDiv = document.createElement("div");
document.body.append(demoDiv);
demoDiv.className = "frames";
var workspace = new Workspace(demoDiv, {className: "demo", title: "", resizeBorderWidth: 7});

if(!window.defines){
    window.defines = {
        baidu(){
            workspace.addFrame({width: 800, height: 600, title: '百度一下，你就知道', icon: './static/images/4.png', src: './static/bdstatic.html', minWidth: 200, minHeight: 200});
        },
        chrome(){
            workspace.addFrame({width: 800, height: 600, title: '百度一下，你就知道', icon: './static/images/4.png', src: './static/bdstatic.html', minWidth: 200, minHeight: 200});
        },
        gitee(){
            window.open('https://gitee.com');
        },
        g9d(){
            workspace.addFrame({width: 800, height: 600, title: 'G9D', icon: './static/images/14.png', src: 'http://g9d.site', minWidth: 200, minHeight: 200});
        }
    };
    window.apps = {
        baidu: {
            favicon: '/images/4.png',
            name: '百度'
        },
        chrome: {
            favicon: '/images/3.png',
            name: 'Google Chrome'
        },
        gitee: {
            favicon: '/images/12.png',
            name: 'Gitee'
        },
        g9d: {
            favicon: '/images/14.png',
            name: 'G9D'
        }
    };
    /* createFrame(列数, 行数) */
    function createFrame(wapp, happ){
        var table = document.querySelector("#apps");
        var tr = document.createElement('tr');
        for(var s = 0; s < wapp; s++){
            var th = document.createElement('th');
            tr.append(th);
        }
        table.append(tr);
        for(var i = 0; i < happ; i++){
            var tr = document.createElement('tr');
            for(var j = 0; j < wapp; j++){
                var td = document.createElement('td');
                tr.append(td);
            }
            table.append(tr);
        }
    }
    createFrame(11, 5);





    var apps = [
        new App('baidu', 0, 0), 
        new App('chrome', 1, 0), 
        new App('gitee', 0, 1),
        new App('g9d', 0, 2)
    ];
    apps.forEach(function(x){x.render()});

}